//
//  GHOrderFooterView.m
//  GodHorses
//
//  Created by Mac on 2017/11/20.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "GHOrderFooterView.h"
@interface GHOrderFooterView()
@property(nonatomic, strong) STLabel                     *payLable;//应付款
@property(nonatomic, strong) STLabel                     *yueLable;//余额
@property(nonatomic, strong) STLabel                     *shenmaLable;//神马lable
@end
@implementation GHOrderFooterView

+ (CGFloat)footerHeight{
    return 160 + 10 + 40 +10;
}
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithReuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, [GHOrderFooterView footerHeight] - 10)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:whiteView];
    
    self.payLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 40)
                                                     text:@"共两件商品,应付款 3600"
                                                textColor:GH_redColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.payLable];
    
    self.yueLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.payLable.st_bottom, UIScreenWidth - 20, 40)
                                              text:@"可用余额：20：00"
                                         textColor:GH_redColor
                                              font:14
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.yueLable];
    
    self.shenmaLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.yueLable.st_bottom, UIScreenWidth - 20, 40)
                                              text:@"可用神马值：0.00"
                                         textColor:GH_redColor
                                              font:14
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.shenmaLable];
    
    self.jifenButton = [[STButton alloc] initWithFrame:CGRectMake(0, self.shenmaLable.bottom, UIScreenWidth - 20, 40)
                                                     title:@"使用积分抵扣0元(仅限余额支付)"
                                                titleColor:GH_secendTextColor
                                                 titleFont:14
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"PC_gouxuan_background"]];
    self.jifenButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    self.jifenButton.selected = YES;
    self.jifenButton.right = UIScreenWidth - 10;
   // self.jifenButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    [self.jifenButton setImage:[UIImage imageNamed:@"PC_gouxuan__selected_red"] forState:UIControlStateSelected];
    [whiteView addSubview:self.jifenButton];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(10, self.jifenButton.bottom , UIScreenWidth - 20, 0.5)];
    line.backgroundColor = GH_lineColor;
    [whiteView addSubview:line];
    self.shenmaPayButton = [[STButton alloc] initWithFrame:CGRectMake(0, self.jifenButton.st_bottom+10, 80, 30)
                                                     title:@"神马值付款"
                                                titleColor:GH_YellowBackGroundColor
                                                 titleFont:13
                                              cornerRadius:8
                                           backgroundColor:[UIColor whiteColor]
                                           backgroundImage:nil
                                                     image:nil];
    self.shenmaPayButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    self.shenmaPayButton.st_right = UIScreenWidth - 10;
    [self.shenmaPayButton st_setBorderWith:1 borderColor:GH_YellowBackGroundColor cornerRadius:8];
    [whiteView addSubview:self.shenmaPayButton];
    //确认收货
    self.shouhuoButton = [[STButton alloc] initWithFrame:CGRectMake(0, self.shenmaPayButton.top, 80, 30)
                                                     title:@"确认收货"
                                                titleColor:GH_YellowBackGroundColor
                                                 titleFont:13
                                              cornerRadius:8
                                           backgroundColor:[UIColor whiteColor]
                                           backgroundImage:nil
                                                     image:nil];
    self.shouhuoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    self.shouhuoButton.st_right = UIScreenWidth - 10;
    self.shouhuoButton.hidden = YES;
    [self.shouhuoButton st_setBorderWith:1 borderColor:GH_YellowBackGroundColor cornerRadius:8];
    [whiteView addSubview:self.shouhuoButton];
    //评价
    self.pingjiaButton = [[STButton alloc] initWithFrame:CGRectMake(0, self.shenmaPayButton.top, 80, 30)
                                                   title:@"商品评价"
                                              titleColor:GH_YellowBackGroundColor
                                               titleFont:13
                                            cornerRadius:8
                                         backgroundColor:[UIColor whiteColor]
                                         backgroundImage:nil
                                                   image:nil];
    self.pingjiaButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    self.pingjiaButton.st_right = UIScreenWidth - 10;
    self.pingjiaButton.hidden = YES;
    [self.pingjiaButton st_setBorderWith:1 borderColor:GH_YellowBackGroundColor cornerRadius:8];
    [whiteView addSubview:self.pingjiaButton];
    
    
    self.payButton = [[STButton alloc] initWithFrame:CGRectMake(0, self.shenmaPayButton.top, 70, 30)
                                                     title:@"余额付款"
                                                titleColor:GH_YellowBackGroundColor
                                                 titleFont:13
                                              cornerRadius:8
                                           backgroundColor:[UIColor whiteColor]
                                           backgroundImage:nil
                                                     image:nil];
    self.payButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    self.payButton.st_right = self.shenmaPayButton.st_left - 5 ;
    [self.payButton st_setBorderWith:1 borderColor:GH_YellowBackGroundColor cornerRadius:8];
    [whiteView addSubview:self.payButton];
    
    self.cancleButton = [[STButton alloc] initWithFrame:CGRectMake(0, self.shenmaPayButton.top, 65, 30)
                                               title:@"取消订单"
                                          titleColor:GH_firstTextColor
                                           titleFont:13
                                        cornerRadius:8
                                     backgroundColor:[UIColor whiteColor]
                                     backgroundImage:nil
                                               image:nil];
    self.cancleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    self.cancleButton.st_right = self.payButton.st_left - 5  ;
    [self.cancleButton st_setBorderWith:1 borderColor:GH_firstTextColor cornerRadius:8];
    [whiteView addSubview:self.cancleButton];
    
}
- (void)setModel:(GHOrderModel *)model{
    _model = model;
    self.cancleButton.hidden = NO;
    self.jifenButton.selected = model.jifenSelected;
    self.payButton.hidden = NO;
    self.shenmaPayButton.hidden = NO;
    self.shouhuoButton.hidden = YES;
    self.pingjiaButton.hidden = YES;
    self.jifenButton.hidden = YES;
    // 订单状态 订单状态0待支付订单1待发货订单2待收货订单3待评价订单4已完成订单 5 已取消
    switch (model.order_status) {
        case 0:
        {
            self.jifenButton.hidden = NO;
            self.cancleButton.hidden = NO;
            self.pingjiaButton.hidden = YES;
            self.shouhuoButton.hidden = YES;
            self.payButton.hidden = NO;
            self.shenmaPayButton.hidden = NO;
            self.cancleButton.right = self.payButton.left - 5;
            
        }
            break;
        case 1:
        {
            //待发货
            self.cancleButton.hidden = NO;
            self.shouhuoButton.hidden = YES;
            self.pingjiaButton.hidden = YES;
            self.payButton.hidden = YES;
            self.shenmaPayButton.hidden = YES;
            self.cancleButton.right = UIScreenWidth - 10;
        }
            break;
        case 2:
        {
            //待收货
            self.jifenButton.hidden = YES;
            self.cancleButton.hidden = YES;
            self.payButton.hidden = YES;
            self.shenmaPayButton.hidden = YES;
            self.pingjiaButton.hidden = YES;
            self.shouhuoButton.hidden = NO;
        }
            break;
        case 3:
        {
            //待评价
            self.jifenButton.hidden = YES;
            self.cancleButton.hidden = YES;
            self.payButton.hidden = YES;
            self.shenmaPayButton.hidden = YES;
            self.pingjiaButton.hidden = NO;
            self.shouhuoButton.hidden = YES;
            
        }
            break;
        case 4:
        {
            self.jifenButton.hidden = YES;
            self.cancleButton.hidden = YES;
            self.payButton.hidden = YES;
            self.shenmaPayButton.hidden = YES;
            self.pingjiaButton.hidden = YES;
            self.shouhuoButton.hidden = YES;
        }
            break;
        case 5:
        {
            self.jifenButton.hidden = YES;
            self.cancleButton.hidden = YES;
            self.payButton.hidden = YES;
            self.shenmaPayButton.hidden = YES;
            self.pingjiaButton.hidden = YES;
            self.shouhuoButton.hidden = YES;
        }
            break;
        default:
            break;
    }
    [self.jifenButton setTitle:[NSString stringWithFormat:@"  使用积分抵扣%@元（仅限余额支付）",model.can_jifen]
                      forState:UIControlStateNormal];
    
    NSInteger num = 0;
    CGFloat allPrice = 0;
    for (GHOrderGoodModel * good in _model.goodList) {
        num = num + [good.g_num integerValue];
        allPrice = allPrice + [good.total_price floatValue];
    }
    
    self.payLable.text = [NSString stringWithFormat:@"共%ld件商品   应付款:  ￥%0.2f",num,allPrice];
    self.payLable.attributedText = [self.payLable.text st_convertAttributeStringWithKeyWord:[NSString stringWithFormat:@"共%ld件商品   应付款:",num] attributes:@{NSForegroundColorAttributeName:GH_secendTextColor}];
    ;

    
    self.yueLable.text = [NSString stringWithFormat:@"可用余额:  ￥%@",model.u_money];
    self.yueLable.attributedText = [self.yueLable.text st_convertAttributeStringWithKeyWord:[NSString stringWithFormat:@"可用余额:"] attributes:@{NSForegroundColorAttributeName:GH_secendTextColor}];
    
    self.shenmaLable.text = [NSString stringWithFormat:@"可用神马值:  ￥%@",model.now_wfpoints];
    self.shenmaLable.attributedText = [self.shenmaLable.text st_convertAttributeStringWithKeyWord:[NSString stringWithFormat:@"可用神马值:"] attributes:@{NSForegroundColorAttributeName:GH_secendTextColor}];
    
}
@end
